package com.ychug.framework.config;


import com.ychug.framework.business.consts.FrontConst;
import com.ychug.framework.util.FreemarkerUtile;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * freemarker配置类
 * @author dds (yadong.zhang0415(a)gmail.com)
 * @version 1.0
 * @website https://www.zhyd.me
 * @date 2019/6/22 16:26
 * @since 1.0
 */
@Configuration
public class FreeMarkerConfig {

    @Autowired
    protected freemarker.template.Configuration configuration;

    @PostConstruct
    public void freemarkerInit(){
        try {
            configuration.setSharedVariable(FrontConst.DIRECTIVE_PREFIX, FreemarkerUtile.initTemplate());
        } catch (TemplateModelException e) {
            e.printStackTrace();
        }

        // •AUTO_DETECT_TAG_SYNTAX: 可以自定义格式，系统会选择第一个标签作为参照；
        // •ANGLE_BRACKET_TAG_SYNTAX: 使用尖括号；
        // •SQUARE_BRACKET_TAG_SYNTAX: 使用方括号；
        configuration.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);
        configuration.setWhitespaceStripping(true);
        configuration.setClassicCompatible(true);

        configuration.setNumberFormat("0.######");
        configuration.setBooleanFormat("true,false");
        configuration.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
        configuration.setDateFormat("yyyy-MM-dd");
        configuration.setTimeFormat("HH:mm:ss");
    }


    public freemarker.template.Configuration getConfiguration() {
        return configuration;
    }

    public void setConfiguration(freemarker.template.Configuration configuration) {
        this.configuration = configuration;
    }
}
